package com.ddf.pluto.controller;

import com.alibaba.fastjson.JSON;
import com.ddf.publics.entity.Conversion;
import com.ddf.publics.entity.User;
import com.ddf.publics.service.ConversionService;
import com.ddf.publics.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.security.Principal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @program: dingding-financial
 * @description: 积分操作
 * @author: Mr.pluto
 * @create: 2020-07-03 11:28
 **/
@Controller
@RequestMapping("/integral")
public class IntegralController {

    @Resource
    private ConversionService conversionService;

    @Autowired
    private LoginService loginService;

    @RequestMapping("/tointegralList")
    public String tointegralList(){
        return "userInfo/integral_list";
    }

        @RequestMapping("/integralListJson")
    @ResponseBody
    public String integralListJson(Principal principal,Integer limit,Integer page){
        Conversion conversion = new Conversion();
        User user = loginService.queryByPhone(principal.getName());
        conversion.setUserId(user.getId());
        List<Conversion> list = conversionService.getAllByCon(conversion,(page-1)*limit,limit);
        int count = conversionService.getListCount(user.getId());
        Map map = new HashMap();
        map.put("code",0);
        map.put("msg","");
        map.put("count",count);
        map.put("data",list);

        return JSON.toJSONString(map);
    }


}
